import os
import json
import csv
name1=None
students=[]
student={}
techer_student={}
def register():   #注册老师
    teacher={}
    print("教师注册")
    teacher["name"] = input('请输入教师的姓名')
    teacher["passwd"] = input('请输入您的密码')
    try:
        open('techer.json')
    except(FileNotFoundError):
        x1=str(teacher)      
    else:
        x1=(','+str(teacher))
        # x1=json.dumps(x11) 
    with open("techer.json", "a") as user:
        user.write(x1)

def loading():   #验证老师
    load_teacher={}
    with open('techer.json','r') as load:
        x122=load.read()
        # x1=eval('['+x122+']')
        x1=eval(x122)
        # print(type(x1))
        # print(x1)
        print('教师登录')
        load_teacher["name"] = input('请输入教师的姓名')
        load_teacher["passwd"] = input('请输入您的密码')
        for _each in x1:
            if load_teacher== _each:
                global name1
                name1=load_teacher['name']
                print('登录成功')
                return True
                x1=open(name1+'.csv','a')
                x1.close()
        else:
            print('登录失败')
            return False
            exit()
            
        
            


def add_student():
    global students
    ok=True
    while ok:
        student={}
        student['name']=str(input('请输入姓名'))
        student['phone']=input('请输入手机')
        student['qq']=input('请输入qq')
        students.append(student)
        if exit==input('exit'):
            ok=False


    try:
        open('student.json')
    except(FileNotFoundError) or student is None:
        x1=str(student)      
    else:
        x1=(','+str(student))
        # x1=json.dumps(x11) 
    with open(name1+'.csv', "a") as user:
        user.write(x1)
    

    if name1==None:
        exit()
    # else:
    #     with open(name1+'csv','r') as load1:
    #         x122=load1.read()
    #         # x1=eval('['+x122+']')
    #         x1=eval(x122)
    #         techer_student['name']=name1
    #         techer_student['student']=x1
    # print(techer_student)
        
        
        
# register()
loading()  
add_student()
print(students)